#ifdef WX_PRECOMP
#include "wx_pch.h"
#else
#include <wx/wx.h>
#endif //WX_PRECOMP

#include "race_parser.h"
#include "exchanger.h"

// Parce one item from XML document
bool RaceParser::OnParceComplete()
{
  Result.push_back(Item);
  Item.Clear();
  return true;
}

const RaceItemVectorType& RaceParser::GetResult() const
{
  return Result;
}

RaceParser::RaceParser()
{
  SetHandler(wxT("id"), &Item.ID, Exchanger::ForInteger());
  SetHandler(wxT("name"), &Item.Name, Exchanger::ForString());

  SetHandler(wxT("speed"), &Item.BonusSpeed, Exchanger::ForDouble());
  SetHandler(wxT("defence"), &Item.BonusDefence, Exchanger::ForDouble());
  SetHandler(wxT("prices"), &Item.BonusPrice, Exchanger::ForDouble());
  SetHandler(wxT("civil_production"), &Item.BonusCivilProduction, Exchanger::ForDouble());
  SetHandler(wxT("military_production"), &Item.BonusMilitaryProduction, Exchanger::ForDouble());
  SetHandler(wxT("hitpoints"), &Item.BonusHitPoints, Exchanger::ForDouble());
  SetHandler(wxT("damage"), &Item.BonusDamage, Exchanger::ForDouble());
  SetHandler(wxT("stealth"), &Item.BonusStealth, Exchanger::ForDouble());
  SetHandler(wxT("detection"), &Item.BonusDetection, Exchanger::ForDouble());
}

void RaceParser::Clear()
{
  Item.Clear();
  Result.clear();
}
